package setting

import (
	"context"
	"github.com/cloudwego/hertz/pkg/common/hlog"
	"mall_admin_api/biz/model/admin_administrator"
	"mall_admin_api/biz/pack"
)

func (s *Setting) GetAdministratorInfo(ctx context.Context) (*admin_administrator.Administrator, error) {
	administrator, err := s.dao.AdministratorDAO.GetAdministratorInfoByID(ctx, s.commonInfo.GetAdministratorInfo().ID)
	if err != nil {
		hlog.CtxErrorf(ctx, "GetAdministratorInfo failed: %v", err)
		return nil, err
	}

	permissions, err := s.dao.AdminRoleMenuRelationDAO.GetPermissionByAdminID(ctx, administrator.ID)
	if err != nil {
		hlog.CtxErrorf(ctx, "dal GetPermissionByAdminID err: %v", err)
		return nil, err
	}
	return pack.GetAdministratorInfo(administrator, permissions), nil
}
